#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define maxl 1000010

int readd(){
    char c;
    int x=0;
    int f=1;
    c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1;
        c=getchar();
    }
    while('0'<=c&&c<='9'){
        x=x*10+(c-'0');
        c=getchar();
    }
    return x*f;
}

int n,m,L,V,stl[maxl],v[maxn],d[maxn],a[maxn],p[maxn];
pair<int,int> cl[maxn];

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    t=readd();
    while(t--){
        n=readd(); m=readd(); L=readd(); V=readd();
        for(int i=0;i<=L;i++){
            stl[i]=-1;
        }
        for(int i=0;i<n;i++){
            d[i]=readd(); v[i]=readd(); a[i]=readd();
            if(a[i]==0){
                if(v[i]>V) cl[i].second=d[i],cl[i].first=L;
                else cl[i].second=-1, cl[i].first=-1;
            }
            else if(a[i]>0){
                if(v[i]>V)cl[i].second=d[i],cl[i].first=L;
                else if(v[i]==V){
                    cl[i].second=d[i]+1,cl[i].first=L;
                }
                else{
                    int endloc=V*V-v[i]*v[i];
                    cl[i].second=(d[i]+endloc/2/a[i]+1);
                    cl[i].first=L;
                }
            }
            else{
                if(v[i]<=V)cl[i].second=cl[i].first=-1;
                else{
                    int endloc=v[i]*v[i]-V*V;
                    a[i]=-a[i];
                    cl[i].first=(d[i]+endloc/2/a[i]-((endloc%(2*a[i]))==0?1:0));
                    cl[i].second=d[i];
                }
            }
            if(cl[i].first>L)cl[i].first=L;
            if(cl[i].second>cl[i].first) cl[i].second=cl[i].first=-1;
        }
        for(int i=0;i<m;i++){p[i]=readd(); stl[p[i]]=p[i];}
        for(int i=1;i<=L;i++){
            stl[i]=max(stl[i],stl[i-1]);
        }
        int sum=0,need=0;
        for(int i=0;i<n;i++){
            if(cl[i].second==-1||cl[i].first==-1) continue;
            if(stl[cl[i].first]>=cl[i].second)sum++;
        }
        sort(cl,cl+n);
        int last=-1;
        for(int i=0;i<n;i++){
            if(cl[i].first==-1||cl[i].second==-1||stl[cl[i].first]<cl[i].second||last>=cl[i].second) continue;
            need++;
            last=stl[cl[i].first];
        }
        cout<<sum<<' '<<m-need<<'\n';
    }

    return 0;
}
/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 -2
6 4 -4
2 5 8 9 15
*/
